package com.tzy.user.service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tzy.common.entity.ShippingAddress;
import com.tzy.user.mapper.ShippingAddressMapper;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * <p>
 * 收货地址表 服务实现类
 * </p>
 *
 * @author 谭同学
 * @since 2022-03-26
 */
@Service
public class ShippingAddressService extends ServiceImpl<ShippingAddressMapper, ShippingAddress> implements IShippingAddressService {
    /**
     * 插入一条记录（选择字段，策略插入）
     *
     * @param entity 实体对象
     */
    @Override
//    @CacheEvict(allEntries = true)
    public boolean save(ShippingAddress entity) {
        return super.save(entity);
    }

//    @Cacheable(cacheNames = "list")
    public List<ShippingAddress> list(int userId) {
        QueryWrapper<ShippingAddress> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        return super.list(queryWrapper);
    }

    /**
     * 查询所有
     */
    @Override
    @Cacheable(cacheNames = "list")
    public List<ShippingAddress> list() {
        return super.list();
    }

    /**
     * 查询列表
     * @param queryWrapper 实体对象封装操作类 {@link QueryWrapper}
     */
    @Override
    public List<ShippingAddress> list(Wrapper<ShippingAddress> queryWrapper) {
        return super.list(queryWrapper);
    }
    /**
     * 根据 ID 选择修改
     *
     * @param entity 实体对象
     */
    @Override
    @CacheEvict(value = {"list"},allEntries = false)
    public boolean updateById(ShippingAddress entity) {
        return super.updateById(entity);
    }
}
